﻿@{
    WebSecurity.RequireAuthenticatedUser();
    Layout = "~/_SiteLayout.cshtml";
    Page.Region = RefDataManager.GetRegionLkUpVal();
    Page.IDType = RefDataManager.GetIDTypeLkUpVal();
    Page.Title="File Upload";
    
    
}
@{
    if (IsPost) {
        var fileData = Request.Files[0];
        var destFolder = Request["folder"];
        var fileName = Path.GetFileName(fileData.FileName);
        var fileSavePath = Server.MapPath("~" + destFolder + fileName);
        fileData.SaveAs(fileSavePath);
    }
}
        <link href="/Styles/uploadify.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="@Href("/uploadify/jquery-1.4.2.min.js")"></script>
        <script type="text/javascript" src="@Href("/uploadify/swfobject.js")"></script>
        <script type="text/javascript" src="@Href("/uploadify/jquery.uploadify.v2.1.4.min.js")"></script>
        <script type="text/javascript" src="@Href("/js/jquery-ui-1.8.18.custom.min.js")"></script>
        <script type="text/javascript" src="/js/jMenu.jquery.min.js"></script>
        <div id="demo">
       
        
            <script type="text/javascript">
                $(function() {
                    $("#uploadType").change(function(){
                       var type= $(this).val()
                       //alert(type);
                       if(type=='activation'){
                            $("#folderPath").val("/upload/Activation/");
                            $('#file_upload').uploadifySettings('folder','/upload/Activation/');
                        }
                       if(type=='delivery'){
                            $("#folderPath").val("/upload/Delivery/");
                             $('#file_upload').uploadifySettings('folder','/upload/Delivery/');
                        }
                         if(type=='ccnos'){
                            $("#folderPath").val("/upload/CCNumbers/");
                             $('#file_upload').uploadifySettings('folder','/upload/CCNumbers/');
                        }
                        
                      
                        
                    });
                    
                    showSpinner();
                    
                   
                   $('#file_upload').uploadify({
                        'uploader'       : '/uploadify/uploadify.swf',
                        'script'         : '@Request.FilePath',
                        'cancelImg'      : '/uploadify/cancel.png',
                        'folder'         : '/upload/Activation/',
                        'multi'          : true,
                        //'auto'           : true,
                        'fileExt'        : '*.xls;*.gif;*.png',
                        'fileDesc'       : 'Image Files (.XLS .JPG, .GIF, .PNG)',
                        'queueID'        : 'queue',
                        'queueSizeLimit' : 3,
                        'simUploadLimit' : 3,
                        'sizeLimit'   : 1000000,
                        'removeCompleted': false,
                        'onSelectOnce'   : function(event,data) {
                            $('#status-message').text(data.filesSelected + ' files have been added to the queue.');
                           
                            },
                        'onAllComplete'  : function(event,data) {
                         
                            $('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.');
                             processUploadedFile();
                            }
                           
                    });
                    
                    $("#dialog").dialog({
                         autoOpen:false,
                        modal:true,
                        resizable:false,
                        draggable:false,
                        position:"center",
                        width:400,
                        height:300,
                        buttons:{
                            "Ok":{
                                text:"Ok",
                                click:function(){
                                    $(this).dialog("close");
                                }
                            }
                        }
                        
                    });
                });
                
                function processUploadedFile(){
                       var data = $("#uploadForm").serialize();
                       var uploadType = $("#uploadType").val();
                       $.post("/Customer/Services/CustomerService/upload/"+uploadType,data,
                        function(data){
                       //show waiting animation
                       showMessage(data[0]);
                    },"json");
                }
                
                function showMessage(message){
                     $("#dialog").html("<p>"+message+"</p>");
                     $("#dialog").dialog("open");
                }
                
               
                
            </script>
             <form id="uploadForm">
                <div id="dialog" title="File Upload"></div>
                <div id="spinner" class="spinnerContent" style="display:none;border:1px solid black">
                    <img id="img-spinner" src="@Href("/images/ajax-loader.gif")" alt="Loading"/>
                    <p>Processing cash cards please wait...</p>
                </div>
                <div id="spinnerBG"></div>
                <label for="uploadType">Upload Type:</label>
                <select name="uploadType" id="uploadType">
                    <option value="activation">Card Activation</option>
                    <option value="delivery">Card Delivery</option>
                    <option value="ccnos">Cash Card Number Assignment</option>
                    
                    
                </select>
                <input type="hidden" id="folderPath" name="folderPath"/>
            </form>
            <div class="demo-box">
                <div id="status-message">Select some files to upload:</div>
                <div id="queue"></div>
                <input id="file_upload" type="file" name="Filedata" />
                <a href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a>
            </div>
           
        </div>
 